@echo off
SET BASE_PATH=bin
SET SERVER_PATH=%BASE_PATH%\server
SET CLIENT_PATH=%BASE_PATH%\client
md %BASE_PATH%
md %SERVER_PATH%
md %CLIENT_PATH%
md assets\client\tls\
md assets\server\tls\
echo will creat the certificate
SET /p NGROK_DOMAIN=input your domain:
::SET NGROK_DOMAIN=
::
openssl genrsa -out client.key 2048
openssl req --config openssl.cnf -new -x509 -nodes -key client.key -days 10000 -subj "/CN=%NGROK_DOMAIN%" -out client.pem
openssl genrsa -out server.key 2048
openssl req --config openssl.cnf -new -key server.key -subj "/CN=%NGROK_DOMAIN%" -out server.csr
openssl x509 -req -in server.csr -CA client.pem -CAkey client.key -CAcreateserial -days 10000 -out server.crt

del client.key
del client.srl
del server.csr
move client.pem assets\client\tls\ngrokroot.crt
move server.crt assets\server\tls\snakeoil.crt
move server.key assets\server\tls\snakeoil.key

echo ngrokd -domain="%NGROK_DOMAIN%" -httpAddr=":81" -httpsAddr=":443" -tunnelAddr=":4443">%SERVER_PATH%\server.bat
echo ./ngrokd -domain="%NGROK_DOMAIN%" -httpAddr=":81" -httpsAddr=":443" -tunnelAddr=":4443">%SERVER_PATH%\server.sh



echo @echo OFF >%CLIENT_PATH%\client.bat
echo color 0a>>%CLIENT_PATH%\client.bat
echo Title Ngrok Start Tool by:HaiLaz>>%CLIENT_PATH%\client.bat
echo Mode con cols=109 lines=30>>%CLIENT_PATH%\client.bat
echo :START>>%CLIENT_PATH%\client.bat
echo ECHO.>>%CLIENT_PATH%\client.bat
echo Echo                  ==========================================================================>>%CLIENT_PATH%\client.bat
echo ECHO.>>%CLIENT_PATH%\client.bat
echo Echo                                       Ngrok Start Tool>>%CLIENT_PATH%\client.bat
echo ECHO.>>%CLIENT_PATH%\client.bat
echo ECHO.>>%CLIENT_PATH%\client.bat
echo Echo                  ==========================================================================>>%CLIENT_PATH%\client.bat
echo Echo.>>%CLIENT_PATH%\client.bat
echo echo.>>%CLIENT_PATH%\client.bat
echo echo.>>%CLIENT_PATH%\client.bat
echo :TUNNEL>>%CLIENT_PATH%\client.bat
echo Echo               input subdomain,eg:"test" ,that give subdomain for you:"test.ngrok.xiao3.top">>%CLIENT_PATH%\client.bat
echo ECHO.>>%CLIENT_PATH%\client.bat
echo ECHO.>>%CLIENT_PATH%\client.bat
echo ECHO.>>%CLIENT_PATH%\client.bat
echo set /p clientid=   input subdomain:>>%CLIENT_PATH%\client.bat
echo echo.>>%CLIENT_PATH%\client.bat
echo set /p port=   input your web server port:>>%CLIENT_PATH%\client.bat
echo ngrok -config=ngrok.cfg -subdomain %%clientid%% %%port%%>>%CLIENT_PATH%\client.bat
echo PAUSE>>%CLIENT_PATH%\client.bat
echo goto TUNNEL>>%CLIENT_PATH%\client.bat

echo ./ngrok -config=ngrok.cfg -subdomain %%clientid%% %%port%%>%CLIENT_PATH%\client.sh

echo server_addr: "%NGROK_DOMAIN%:4443">%CLIENT_PATH%\ngrok.cfg
echo trust_host_root_certs: false>>%CLIENT_PATH%\ngrok.cfg